package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Log;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.common.enums.BusinessType;
import com.lakeworks.domain.OprAttachment;
import com.lakeworks.service.IOprAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 衣物附件Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/opr/attachment")
public class OprAttachmentController extends BaseController {
    private String prefix = "opr/system/attachment";

    @Autowired
    private IOprAttachmentService oprAttachmentService;

    /**
     * 查询
     */
    @GetMapping("/list")
    public TableDataInfo list(@RequestBody OprAttachment oprAttachment) {
        startPage();
        List<OprAttachment> list = oprAttachmentService.selectOprAttachmentList(oprAttachment);
        return getDataTable(list);
    }

//    /**
//     * 导出
//     */
//    @Log(title = "入厂附件", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public AjaxResult export(OprAttachment oprAttachment)
//    {
//        List<OprAttachment> list = oprAttachmentService.selectOprAttachmentList(oprAttachment);
//        ExcelUtil<OprAttachment> util = new ExcelUtil<OprAttachment>(OprAttachment.class);
//        return util.exportExcel(list, "入厂附件数据");
//    }

    /**
     * 新增保存
     */
    @Log(title = "入厂附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addSave(@RequestBody OprAttachment oprAttachment) {
        return toAjax(oprAttachmentService.insertOprAttachment(oprAttachment));
    }

    /**
     * 修改
     */
    @PutMapping("/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OprAttachment oprAttachment = oprAttachmentService.selectOprAttachmentById(id);
        mmap.put("oprAttachment", oprAttachment);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @Log(title = "入厂附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult editSave(OprAttachment oprAttachment) {
        return toAjax(oprAttachmentService.updateOprAttachment(oprAttachment));
    }

    /**
     * 删除
     */
    @Log(title = "入厂附件", businessType = BusinessType.DELETE)
    @DeleteMapping
    public AjaxResult remove(String ids) {
        return toAjax(oprAttachmentService.deleteOprAttachmentByIds(ids));
    }
}
